<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
    <head>
        <th:block th:include="include :: header('课程信息列表')" />
        <th:block th:include="include :: layout-latest-css" />
        <th:block th:include="include :: ztree-css" />
    </head>
    <body class="gray-bg">
        <div class="ui-layout-west">
            <div class="box box-main">
                <div class="box-header">
                    <div class="box-title">
                        <i class="fa icon-grid"></i> 学科管理
                    </div>
                    <div class="box-tools pull-right">
                        <a type="button" class="btn btn-box-tool" href="#" onclick="subject()" title="学科管理"><i
                                class="fa fa-edit"></i></a>
                        <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;">
                            <i class="fa fa-chevron-up"></i></button>
                        <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                                class="fa fa-chevron-down"></i></button>
                        <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i
                                class="fa fa-refresh"></i></button>
                    </div>
                </div>
                <div class="ui-layout-content">
                    <div id="tree" class="ztree"></div>
                </div>
            </div>
        </div>
        <div class="ui-layout-center">
            <div class="container-div">
                <div class="row">
                    <div class="col-sm-12 search-collapse">
                        <form id="formId">
                            <div class="select-list">
                                <ul>
                                    <li>
                                        <label>课程名称：</label>
                                        <input type="text" name="courseName"/>
                                    </li>
                                    <li style="width: 270px;">
                                        <label>所属学科：</label>
                                        <div class="input-group">
                                            <input id="treeId" name="subjectId" type="hidden" />
                                            <input class="form-control" type="text" onclick="selectManageTree()" id="treeName" readonly="true" >
                                            <span class="input-group-addon" ><i class="fa fa-remove" id="clearBtn"></i></span>
                                        </div>
                                    </li>
                                    <li>
                                        <label>课程学分：</label>
                                        <select name="courseScore" th:with="type=${@dict.getType('course_score_value')}">
                                            <option value="">所有</option>
                                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                        </select>
                                    </li>
                                    <li>
                                        <label>项目类型：</label>
                                        <select name="projectType" th:with="type=${@dict.getType('course_project_type')}">
                                            <option value="">所有</option>
                                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                        </select>
                                    </li>
                                    <li>
                                        <label>状态：</label>
                                        <select name="visible">
                                            <option value="">所有</option>
                                            <option value="0">显示</option>
                                            <option value="1">隐藏</option>

                                        </select>
                                    </li>
                                    <li>
                                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                    </li>
                                </ul>
                            </div>
                        </form>
                    </div>

                    <div class="btn-group-sm" id="toolbar" role="group">
                        <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="biz:course:add">
                            <i class="fa fa-plus"></i> 添加
                        </a>
<!--                        <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:course:edit">-->
<!--                            <i class="fa fa-edit"></i> 修改-->
<!--                        </a>-->
                        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:course:remove">
                            <i class="fa fa-remove"></i> 删除
                        </a>
                        <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="biz:course:export">
                            <i class="fa fa-download"></i> 导出
                        </a>
                    </div>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </div>

        <th:block th:include="include :: footer" />
        <th:block th:include="include :: layout-latest-js" />
        <th:block th:include="include :: ztree-js" />
        <script th:inline="javascript">
            var editFlag = [[${@permission.hasPermi('biz:course:edit')}]];
            var removeFlag = [[${@permission.hasPermi('biz:course:remove')}]];
            var courseScoreDatas = [[${@dict.getType('course_score_value')}]];
            var projectTypeDatas = [[${@dict.getType('course_project_type')}]];
            var courseScoreTypeDatas = [[${@dict.getType('course_score_type')}]];
            var prefix = ctx + "biz/course";

            $(function() {

                var panehHidden = false;
                if ($(this).width() < 769) {
                    panehHidden = true;
                }
                $('body').layout({ initClosed: panehHidden, west__size: 185 });

                var options = {
                    url: prefix + "/list",
                    createUrl: prefix + "/add",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    exportUrl: prefix + "/export",
                    modalName: "课程信息",
                    columns: [

                        {
                            title: '操作',
                            width:220,
                            align: 'center',
                            formatter: function(value, row, index) {
                                var actions = [];
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>添加内容</a> ');
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                return actions.join('');
                            }
                        },
                        {
                            field: 'id',
                            title: 'id',
                            visible: false
                        },
                        {
                            field: 'courseName',
                            title: '课程名称'
                        },
                        {
                            field: 'subjectName',
                            title: '所属学科'
                        },
                        {
                            field: 'coverUrl',
                            title: '课程封面图片',
                            formatter: function(value, row, index) {
                                return '<img src="'+ row.host+ row.coverUrl+'" width="80"/>';
                            }
                        },
                        {
                            field: 'courseScore',
                            title: '课程学分',
                            formatter: function(value, row, index) {
                                return $.table.selectDictLabel(courseScoreDatas, value);
                            }
                        },
                        {
                            field: 'introduce',
                            title: '课程介绍'
                        },
                        {
                            field: 'projectType',
                            title: '项目类型',
                            formatter: function(value, row, index) {
                                return $.table.selectDictLabel(projectTypeDatas, value);
                            }
                        },
                        {
                            field: 'projectNumber',
                            title: '项目编号'
                        },
                        {
                            field: 'projectLeader',
                            title: '项目负责人'
                        },
                        {
                            field: 'projectOrg',
                            title: '项目负责单位'
                        },
                        {
                            field: 'courseScoreType',
                            title: '课程学分类型',
                            formatter: function(value, row, index) {
                                return $.table.selectDictLabel(courseScoreTypeDatas, value);
                            }
                        },
                        {
                            field: 'scoreNumber',
                            title: '课程学分编号'
                        },
                        {
                            field: 'focusScore',
                            title: '关注度'
                        },
                        {
                            field: 'orderNum',
                            title: '显示顺序'
                        },
                        {
                            field: 'visible',
                            title: '状态',
                            formatter: function(value, item, index) {
                                if ('0' == value) {
                                    return '<span class="badge badge-primary">显示</span>'
                                }else{
                                    return '<span class="badge badge-danger">隐藏</span>'
                                }

                            }
                        }
                      ]
                };
                $.table.init(options);

                querySubjectTree()

                $('#btnExpand').click(function() {
                    $._tree.expandAll(true);
                    $(this).hide();
                    $('#btnCollapse').show();
                });

                $('#btnCollapse').click(function() {
                    $._tree.expandAll(false);
                    $(this).hide();
                    $('#btnExpand').show();
                });

                $('#btnRefresh').click(function() {
                    querySubjectTree();
                });

                $('#clearBtn').click(function(){
                    $("#treeId").val('');
                    $("#treeName").val('');
                })
            });

            function subject() {

                var url = ctx + "biz/subject";
                $.modal.openTab("学科管理", url);
            }

            /*学科管理-新增-选择父部门树*/
            function selectManageTree() {
                var options = {
                    title: '学科管理选择',
                    width: "380",
                    url: ctx + "biz/subject/selectManageTree/" + $("#treeId").val(),
                    callBack: treeCallBack
                };
                $.modal.openOptions(options);
            }

            function treeCallBack(index, layero){
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }

            function querySubjectTree()
            {
                var url = ctx + "biz/subject/treeData";
                var options = {
                    url: url,
                    expandLevel: 2,
                    onClick : zOnClick
                };
                $.tree.init(options);

                function zOnClick(event, treeId, treeNode) {
                    $("#treeId").val(treeNode.id);
                    $("#treeName").val(treeNode.name);
                    $.table.search();
                }
            }

            function detail(courseId) {
                var url =  ctx + 'biz/coursedetail/detail/' + courseId;
                $.modal.openTab("添加课程内容", url);
            }
        </script>
    </body>
</html>